package com.wd.visitor.common.service;

import com.hq.dto.*;
import com.hq.service.StaffService;
import com.hq.service.TagService;
import com.wd.visitor.common.domain.entity.Visitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @className: VisitorService
 * @description: TODO 类描述
 * @author: liumingkun
 * @date: 2024/3/12
 **/
@Service
public class VisitorService {

    private final static Logger logger= LoggerFactory.getLogger(VisitorService.class);

    @Resource
    TagService tagService;


    @Resource
    StaffService staffService;

    @Value("${tag-name}")
    private String tagName;


    public FicusResponseSub<List<FicusResponse<PutStaffResultDTO>>>  addVisitor(Visitor visitor) {
        List<String> tagIdList = new ArrayList<>();
        tagIdList.add(getTagId(tagName));
        return createStaff(tagIdList, visitor);
    }

    public String getTagId(String tagName) {

        TagDTO tagDTO = tagService.getTags("STAFF", tagName);
        return tagDTO.tag_id;
    }

    public FicusResponseSub<List<FicusResponse<PutStaffResultDTO>>> createStaff(List<String> tagIdList, Visitor visitor) {

        BatchCreateStaffDTO batchCreateStaffDTO = new BatchCreateStaffDTO();
        List<CreateStaffDTO> staffDTOList = new ArrayList<>();
        batchCreateStaffDTO.staff_list = staffDTOList;

        CreateStaffDTO createStaffDTO = new CreateStaffDTO();
        createStaffDTO.tag_id_list = tagIdList;

        StaffInformationDTO staffInformationDTO = new StaffInformationDTO();
        staffInformationDTO.id = visitor.getPhone();
        staffInformationDTO.name = visitor.getVisitorName();
        createStaffDTO.person_information = staffInformationDTO;

        List<String> faceList = new ArrayList<>();
        faceList.add(visitor.getImg());
        createStaffDTO.face_image_content_list = faceList;
        staffDTOList.add(createStaffDTO);
        FicusResponseSub<List<FicusResponse<PutStaffResultDTO>>> listFicusResponseSub = staffService.addStaffs(batchCreateStaffDTO);
        logger.info("新增人员返回:"+listFicusResponseSub);
        return listFicusResponseSub;

    }

    public static void main(String[] args) {
        TagService tagService = new TagService();
        NewTagDTO tagDTO1 = new NewTagDTO();

        SingleTag singleTag = new SingleTag();
        singleTag.tag_name="GD-TEST";
        List<String> listT=new ArrayList<>();
        listT.add("STAFF");
        singleTag.visible_identity=listT;

        List<SingleTag> list=new ArrayList<>();
        list.add(singleTag);
        tagDTO1.tag_list=list;
        FicusResponseSub<List<FicusResponseSub<TagDTO>>> tags = tagService.createTags(tagDTO1);
        System.out.println(tags);
        FicusResponseSub<List<TagDTO>> staff = tagService.getTags("STAFF");
        List<TagDTO> result = staff.result;
        for (int i = 0; i < result.size() ; i++) {
            TagDTO tagDTO = result.get(i);
            System.out.println(tagDTO.tag_name);
        }
    }

}
